<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title>壹果企画(北京)科技有限公司-销售系统</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">

	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
	<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
	<link rel="stylesheet" type="text/css" href="../../css/responsive.css">
	<!-- STYLESHEETS -->
	<!--[if lt IE 9]><script src="js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- ANIMATE -->
	<link rel="stylesheet" type="text/css" href="../../css/animatecss/animate.min.css" />


	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
	<link rel="stylesheet" href="../../js/datatables/datatable.css">
	<!-- WIZARD -->
	<link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
  <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />

</head>

<body>


	<!-- PAGE -->
	<section id="page">

		<div class="container">
			<div class="row">
				<div id="content" class="col-lg-12">
					<!-- PAGE HEADER-->
					<div class="row">
						<div class="col-sm-12">
							<div class="page-header">
								<!-- STYLER -->
								<!-- /STYLER -->

								<div class="clearfix">
									<h3 class="content-title pull-left">欢迎登录壹果销售系统-销售统计</h3>
									<a class="btn btn-warning add_order" style="margin-left:50px;float: right;margin-top:5px">销售录入</a>
									<a class="btn btn-primary" href="product_list.html" style="float: right;margin-top:5px;display:none">商品管理</a>

								</div>

							</div>
						</div>
					</div>
					<!-- /PAGE HEADER -->
					<div class="row" style=" font-size: 28px;">

						<div class="form-group" style="line-height:34px">
							<label class="col-sm-1 control-label" for="e1" style="width: auto">选择日期：</label>
							<div class="col-sm-2">
								<select id="date_select" class="col-md-12 select2-offscreen" tabindex="-1">
									<option value=-1>请选择</option>
								</select>
							</div>

							<label class="control-label" style="margin-left:10px">总件数：</label>
							<span class="totalAmount" style="color: red;">0</span>
							<label class="control-label" style="margin-left:10px">总金额：</label>
							<span class="totalMoney" style="color: red;">0</span>

							<!-- <a class="btn btn-primary search" style="margin-left:60px">查询</a> -->
						</div>
					</div>

					<div class="row" style="text-align:left; font-size: 14px">

						<table class="datatable table table-striped table-bordered table-hover dataTable no-footer">
							<thead>
								<tr>
									<th width="5%">销售日</th>
									<th width="10%">商品名称</th>
									<th width="5%">颜色</th>
									<th width="10%">SKU编码</th>
									<th width="5%">尺码</th>
									<th width="5%">销售数量</th>
									<th width="5%">库存</th>

								</tr>
							</thead>
							<tbody>

							</tbody>
						</table>
					</div>

				</div>

			</div>
			<!-- /CONTENT-->
		</div>

		</div>
	</section>


	<!--/PAGE -->
  <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
  <script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	<script src="../../js/common.js"></script>
	<script>
		$(function () {

			var domain = window.location.href.substr(0, window.location.href.indexOf("pages"));
			var actionId = $.getUrlParam("actionId");
			var actionName = $.getUrlParam("actionName");

			$('.add_order').click(function () {
				window.location.href = "add_order.html?id=" + actionId + "&actionName=" + actionName;
			})


			var getActionDate = function () {
				$.ajax({
					type: "get",
					url: domain + "admin/action/getActionById.do",
					data: { actionId: actionId },
					async: true,
					success: function (result) {

						var startDate = result.extra.startDate;
						var endDate = result.extra.endDate;
						console.log(startDate + "---------" + endDate)

						var date = startDate;
						console.log(date);
						var html = "<option value=-1>请选择</option>";
						while (date <= endDate) {
							var date_f = $.getLocalDate(date)
							console.log(date_f);
							html += " <option value='" + date_f + "'>" + date_f + "</option>";
							date = new Date(addDate(date, 1));
						}
						console.log(html);

            $("#date_select").html(html);
            $("#date_select").select2();
					}

				});
			}
			var getDiffDays = function (sDate1, sDate2) { //sDate1和sDate2是2017-9-25格式 
				var aDate, oDate1, oDate2, iDays
				aDate = sDate1.split("-")
				oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为9-25-2017格式 
				aDate = sDate2.split("-")
				oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
				iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数 
				return iDays
			}
			var addDate = function (date, days) {
				var d = new Date(date);
				d.setDate(d.getDate() + days);
				var m = d.getMonth() + 1;
				if (m < 10) {
					m = "0" + m;
				}
				return d.getFullYear() + '-' + m + '-' + d.getDate();
			}
			getActionDate();
			var searchReport = function () {
				$("table tbody tr").empty();
				var startDate = $("#date_select").val();

				if (startDate == -1) {
					startDate = null;
					$("table thead th:eq(0)").hide();
				}
				else {
					$("table thead th:eq(0)").show();
				}
				$.ajax({
					type: "get",
					url: domain + "admin/action/getSalesReport.do",
					data: { actionId: actionId, startDate: startDate, endDate: startDate },
					async: true,
					success: function (result) {
						if (result.type === 'success') {
							$(".totalAmount").html(result.extra.totalAmount);
							$(".totalMoney").html(result.extra.totalMoney.toFixed(2));
							$.each(result.extra.reportList, function (index, item) {
								var display = "style='display:none'";
								var str = "";
								if (startDate) {
									str += "<td >" + startDate + "</td>";
								}
								str += "<td>" + item.productName + "</td>";
								str += "<td>" + item.shortName + "</td>";
								str += "<td>" + item.skuCode + "</td>";
								str += "<td>" + item.size + "</td>";
								str += "<td>" + item.totalAmount + "</td>";
								str += "<td>" + item.amount + "</td>";
								$("table tbody").append("<tr>" + str + "</tr>");
							});
						}
					}
				});
			};
      searchReport();
      $("#date_select").change(function() {
        searchReport();
      })
		});
	</script>
</body>

</html>